<template>
	<view>
		<view class="content">
			<view class="title">
				账号信息
			</view>
			<view class="row">
				<view class="nominal">
					角色名
				</view>
				<view class="input">
					<input placeholder="请输入角色名" type="text" v-model="role_name" />
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					子账号
				</view>
				<view class="input">
					<input placeholder="请输入子账号" type="text" v-model="son" />
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					大区
				</view>
				<view class="input">
					<input placeholder="请输入大区" type="text" v-model="zone" />
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					服务器
				</view>
				<view class="input">
					<input placeholder="请输入服务器" type="text" v-model="server" />
				</view>
			</view>
			<view class="title">
				角色信息
			</view>
			<view class="row">
				<view class="nominal">
					拾取天赋
				</view>
				<view class="input">
					<input placeholder="请输入拾取天赋" type="text" v-model="talent" />
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					目前真实装等
				</view>
				<view class="input">
					<input placeholder="请输入目前真实装等" type="text" v-model="eq_level" />
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					职业
				</view>
				<view class="input">
					<uni-data-select v-model="job" :localdata="jobRange"></uni-data-select>
				</view>
			</view>
			<view class="row">
				<view class="nominal">
					阵营
				</view>
				<view class="input">
					<uni-data-select :border="0" v-model="camp" :localdata="campRange"></uni-data-select>
				</view>
			</view>
			<view class="title">
				隐私资料
			</view>
			<view class="row">
				<view class="nominal">
					账号密码
				</view>
				<view class="input">
					<textarea v-model="detailed" auto-height="true" placeholder="请输入游戏账号信息+手机号"></textarea>
				</view>
			</view>
		</view>
		<view class="save" @tap="save">
			<view class="btn">
				保存角色
			</view>
		</view>
	</view>
</template>

<script>
	import {
		roleSave,
		commonParam
	} from "@/api/api.js"
	export default {
		data() {
			return {
				son: '',
				editType: 'edit',
				id: '',
				zone: '',
				detailed: '',
				server: '',
				talent: '',
				job: '',
				jobRange: [],
				camp: '',
				campRange: [],
				eq_level: '',
				role_name: ''
			};
		},
		onLoad(e) {
			this.editType = e.type;
			if (e.type == 'edit') {
				uni.getStorage({
					key: 'role',
					success: (e) => {
						this.id = e.data.id
						this.son = e.data.son_account
						this.zone = e.data.zone
						this.server = e.data.server
						this.job = e.data.job
						this.talent = e.data.talent
						this.camp = e.data.camp
						this.detailed = e.data.remarks
						this.eq_level = e.data.eq_level
						this.role_name = e.data.role_name
					}
				})
			}
			this.commonParam()
		},
		methods: {
			commonParam() {
				commonParam().then(res => {
					if (res.code == 0) {
						let data = res.data
						this.talentRange = data.talent.map(item => {
							return {
								value: item.id,
								text: item.name
							}
						})
						this.jobRange = data.job.map(item => {
							return {
								value: item.id,
								text: item.name
							}
						})
						this.campRange = data.camp.map(item => {
							return {
								value: item.id,
								text: item.name
							}
						})
					}
				})
			},
			roleSave() {
				roleSave({
					id: this.id,
					son_account: this.son,
					zone: this.zone,
					server: this.server,
					job: this.job,
					talent: this.talent,
					camp: this.camp,
					remarks: this.detailed,
					eq_level: this.eq_level,
					role_name: this.role_name
				}).then(res => {
					uni.hideLoading();
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 0) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
					console.log(res);
				})
			},

			save() {
				let data = {
					"son": this.son,
					"zone": this.zone,
					"server": this.server
				}
				if (this.editType == 'edit') {
					data.id = this.id
				}
				if (!data.son) {
					uni.showToast({
						title: '请输入子账号',
						icon: 'none'
					});
					return;
				}
				if (!data.zone) {
					uni.showToast({
						title: '请输入大区',
						icon: 'none'
					});
					return;
				}
				if (!data.server) {
					uni.showToast({
						title: '请输入服务器',
						icon: 'none'
					});
					return;
				}
				uni.showLoading({
					title: '正在提交'
				})
				this.roleSave()
			}
		},
	};
</script>
<style lang="scss">
	page {
		background: #f3f3f3;
	}

	.save {
		view {
			display: flex;
		}

		position: fixed;
		bottom: 0;
		width: 100%;
		height: 120upx;
		display: flex;
		justify-content: center;
		align-items: center;

		.btn {
			width: 90%;
			height: 80upx;
			border-radius: 20upx;
			background-color: #2BC360;
			color: #fff;
			justify-content: center;
			align-items: center;

			.icon {
				height: 80upx;
				color: #fff;
				font-size: 30upx;
				justify-content: center;
				align-items: center;
			}

			font-size: 30upx;
		}
	}

	.content {
		display: flex;
		flex-wrap: wrap;

		view {
			display: flex;
		}

		.title {
			padding: 10px;
			font-weight: bold;
			margin-top: 10px;
			background: transparent;
			width: 100%;
			font-size: 14px;
		}

		.row {
			width: 100%;
			padding: 0 3%;
			border-top: solid 1upx #eee;
			background: #fff;

			.nominal {
				width: 30%;
				height: 100upx;
				font-size: 28upx;
				align-items: center;
			}

			.input {
				width: 70%;
				padding: 20upx 0;
				align-items: center;
				font-size: 28upx;

				&.switch {
					justify-content: flex-end;

				}

				uni-data-select {
					width: 100%;
				}

				switch {
					transform: scale(.7);
				}

				input {
					font-size: 28upx;
				}

				textarea {
					margin: 20upx 0;
					min-height: 120upx;
					width: 100%;
					padding-left: 10px;
					font-size: 14px;
				}
			}

			.del {
				width: 96%;

				height: 80upx;
				border-radius: 20upx;
				justify-content: center;
				align-items: center;
				font-size: 28upx;
				color: #fff;
				background-color: rgba(255, 0, 0, 0.8);
				border-bottom: solid 1upx #eee;
				margin: 10px auto;
			}
		}
	}
</style>